package com.xbongbong.paas.script.controller;

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.saas.service.EventChangeCustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 应用模块名称<p>
 * 代码描述<p>
 * Company: 逍邦网络科技有限公司<p>
 *
 * @author chenshan
 * @version v1.0
 * @since 2022/3/2 10:17
 */
@Controller
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/script/dingtalk/staff")
public class DingtalkStaffLeaveSynController {
    private static final Logger LOG = LoggerFactory.getLogger(DingtalkStaffLeaveSynController.class);
    @Resource
    private EventChangeCustomerService eventChangeCustomerService;
    
    @RequestMapping(value = "/leave", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String leave(@RequestParam("corpid") String corpid, @RequestParam("userId") String userId) {
        XbbResponse<BaseVO> response = new XbbResponse<>();
        try {
            if ( StringUtil.isNotEmpty(corpid) && StringUtil.isNotEmpty(userId) ) {
                eventChangeCustomerService.orgUserLeave(corpid, Arrays.asList(userId));
            }
        } catch (XbbException e) {
            response = new XbbResponse<>(e);
        }
        return JSON.toJSONString(response);
    }
}
